cmake_minimum_required(VERSION 3.22)
project(simple_protocol)

# 为所有目标启用位置无关代码
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# 指定 C++20 标准
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)  # 强制使用指定的标准
set(CMAKE_CXX_EXTENSIONS OFF)  # 禁用编译器特定的扩展（可选）

# 添加子目录 pybind11
add_subdirectory(./lib/pybind11)
add_subdirectory(./lib/simple_protocol)

# 加入 cpp 文件
pybind11_add_module(simple_protocol SHARED ./src/simple_protocol_export.cpp)

# 添加源文件
set(SOURCE_FILES
    .lib/simple_protocol/src/simple_protocol.cpp
)

# add_library(simple_protocol ${SOURCE_FILES})
# 设置输出文件后缀名为 .so
set_target_properties(simple_protocol PROPERTIES SUFFIX ".so")

# 添加包含目录
include_directories(
    include
    src
    lib/pybind11/pybind11/include
    lib/simple_protocol/include
)

# 找到 Python 包
find_package(Python3 REQUIRED COMPONENTS Development)
include_directories(${Python3_INCLUDE_DIRS})

# 添加依赖项
target_link_libraries(simple_protocol
    PRIVATE 
        simple_protocol_lib 
    PUBLIC
        ${Python3_LIBRARIES}
)
